package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.AnalysisManage;
import com.hunttown.mes.rpc.domain.AnalysisManageDTO;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2018-11-26 14:25:41
 */
public class AnalysisManageConverts {

    private static Logger LOG = LoggerFactory.getLogger(AnalysisManageConverts.class);

    public static List<AnalysisManageDTO> convert(List<AnalysisManage> analysisManageList) {
        if (CollectionUtils.isEmpty(analysisManageList)) {
            return Collections.EMPTY_LIST;
        }

        List<AnalysisManageDTO> analysisManageListResult = Lists.newArrayList();
        for (AnalysisManage analysisManage : analysisManageList) {
            analysisManageListResult.add(convert(analysisManage));
        }
        return analysisManageListResult;
    }

    public static AnalysisManageDTO convert(AnalysisManage analysisManage) {
        try {
            return BeanUtils.copy(analysisManage, AnalysisManageDTO.class);
        } catch (Exception e) {
            LOG.error("AnalysisManage到AnalysisManageDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManage到AnalysisManageDTO转换失败", e);
        }
    }

    public static AnalysisManage convert(AnalysisManageDTO analysisManageDTO) {
        try {
            return BeanUtils.copy(analysisManageDTO, AnalysisManage.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageDTO到AnalysisManage转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageDTO到AnalysisManage转换失败", e);
        }
    }
}